package com.ugrow.ugrowcommunity.activity.leave;

import androidx.appcompat.app.AppCompatActivity;

import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.DatePicker;
import android.widget.TimePicker;
import android.widget.Toast;

import com.ugrow.ugrowcommunity.databinding.ActivityLeaveBinding;

import java.util.Calendar;

public class LeaveActivity extends AppCompatActivity {

    private ActivityLeaveBinding binding;
    private String[] reason = new String[]{"病假","事假","其他"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityLeaveBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        //下拉列表
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, reason);
        binding.spinner.setAdapter(arrayAdapter);
        //返回按钮
        binding.back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        //开始时间
        binding.begin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                    //创建DatePickerDialog实例
                    DatePickerDialog datePickerDialog = new DatePickerDialog(LeaveActivity.this);
                    //设置日期监听
                    datePickerDialog.setOnDateSetListener(new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker datePicker, int year, int month, int dayOfMonth) {
                            binding.begin.setText(year + "年/" + (month+1) + "月/" + dayOfMonth + "日");
//                            Log.d("TAG", year + "年" + (month + 1) + "month" + "dayOfMonth" + dayOfMonth);
                        }
                    });
                    //show
                    datePickerDialog.show();
                } else {
                    Toast.makeText(LeaveActivity.this, "系统版本过低", Toast.LENGTH_SHORT).show();
                }
            }
        });
        //结束时间
        binding.end.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                    //创建DatePickerDialog实例
                    DatePickerDialog datePickerDialog = new DatePickerDialog(LeaveActivity.this);
                    //设置日期监听
                    datePickerDialog.setOnDateSetListener(new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker datePicker, int year, int month, int dayOfMonth) {
                            binding.end.setText(year + "年/" + (month+1) + "月/" + dayOfMonth + "日");
//                            Log.d("TAG", year + "年" + (month + 1) + "month" + "dayOfMonth" + dayOfMonth);
                        }
                    });
                    //show
                    datePickerDialog.show();
                } else {
                    Toast.makeText(LeaveActivity.this, "系统版本过低", Toast.LENGTH_SHORT).show();
                }
            }
        });
        //添加照片
        binding.addimg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });

    }
}